package lsg;

/**
 * CustomerArrival is a special SimEvent.
 * At least one CustomerArrival in the EventChain is needed to 
 * start the simulation.
 * @author Alexander Klein
 * @version 1.0.0 
 * @since 2005-10-22
 */
public class CustomerArrival extends SimEvent
{
	/**
	 * Constructor that uses the given argument
	 *@param time Representing the simulation time at which the event occurs
	 */
	public CustomerArrival (long time)
	{
		value = time;
	}
	/**
	 * Function describes the system behavior depending on the serverBusy attribute 
	 * if a CustomArrival occurs.
	 */
	public void process ()
	{
		/**
		 * If server is not busy insert the CustomerArrival in the server and set him to busy state
		 */
		if (s.serverBusy == false) 
		{
			//Insert the next CustomerArrival in the EventChain
			s.ec.insert ((SimEvent) new CustomerArrival (s.now + s.interArrivalTime));
			
			//Insert the ServiceCompletion event in the EventChain
			s.ec.insert ((SimEvent) new ServiceCompletion (s.now + s.serviceCompletionTime));
			
			s.serverBusy = true;
			return;
		}
		/**
		 * If server is busy insert the CustomerArrival in the queue
		 */
		else
		{
			s.ec.insert ((SimEvent) new CustomerArrival (s.now + s.interArrivalTime));
			s.queueSize ++;
		}
	}
}
